//
//  GPSearchBar.m
//  SearchBarTest
//
//  Created by GuoPeng on 16/4/25.
//  Copyright © 2016年 GuoPeng. All rights reserved.
//

#import "GPSearchBar.h"

typedef void(^SearchBlock)(NSString *);

@interface GPSearchBar ()
{
    
}

@property (copy, nonatomic) SearchBlock searchBlock;
@property (strong, nonatomic) NSString *placeStr;

@end

@implementation GPSearchBar

- (instancetype)initWithPlaceholder:(NSString *)placeLabel frame:(CGRect)frame search:(void (^)(NSString *))searchBlock
{
    self = [[[NSBundle mainBundle] loadNibNamed:@"GPSearchBar" owner:self options:nil] objectAtIndex:0];
    if (self) {
        self.frame = frame;
        self.placeStr = placeLabel;
        self.searchBar.placeholder = placeLabel;
        self.searchBlock = searchBlock;
       [[[[self.searchBar.subviews objectAtIndex : 0 ] subviews ] objectAtIndex : 0 ] removeFromSuperview ];
//      [ self.searchBar setBackgroundColor :[ UIColor clearColor ]];
    }
    return self;
    
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [self.searchBar resignFirstResponder];
    self.searchBlock(searchBar.text);
}

@end
